#!/usr/bin/env node

const { getAccessToken, config } = require('./index.js')
const https = require('https')

function deleteRepo( name, owner = "", is_org = false ) {
    console.log( "deleteRepo: " + name + " of " + owner )
    var url = "https://gitee.com/api/v5/repos" + "/" + owner + "/" + name + "?access_token=" + getAccessToken() + "&repo=" + name
    console.log( "url: " + url )

    const req = https.request( url, {
        method: "DELETE"
    }, ( res ) => {
        console.log( "" + res.statusCode )
        console.log("" + res.statusMessage)
    } ).on( "error", ( error ) => {

    } ).end()

}

if (config.type == 'user') {
    console.log("delete must input owner.")
} else if (config.type == 'orgs') {
    deleteRepo(config.owner, config.name, true)
}